﻿using Draco.OWF.Utils;
using System;
using System.Collections.Generic;

namespace Draco.OWF.Metadata
{
    public class ActivityConfiguration : List<DataItem>
    {
        public new void Add(DataItem item)
        {
            base.Add(item);
        }
        public bool Contains(String keyName)
        {
            foreach (DataItem item in this)
            {
                if (keyName == item.Name)
                    return true;
            }
            return false;
        }
        public DataItem GetItem(String keyName)
        {
            foreach (DataItem item in this)
            {
                if (keyName == item.Name)
                    return item;
            }
            return null;
        }

        public void AddDataItem(String name, String value)
        {
            this.Add(new DataItem(name, value));
        }

        public String GetValueString(String name)
        {
            DataItem item = this.GetItem(name);
            if (item != null)
                return item.Value;
            return null;
        }

        public bool GetValueBoolean(String name)
        {
            Object obj = GetValueObject(name);
            return obj == null ? false : (bool)obj;
        }

        public int GetValueInt(String name)
        {
            Object obj = GetValueObject(name);
            return obj == null ? 0 : (int)obj;
        }

        public Object GetValueObject(String name)
        {
            DataItem item = this.GetItem(name);
            if (item != null)
            {
                return TypeConverter.Convert(item.DataType, item.Value);
            }
            return null;
        }
    }
}
